let mysql=require('mysql');
let conf=require('../config/db.js');
let util=require('../util/util.js');
let sql = require('../service/booksql.js');
let pool = mysql.createPool(util.extend({}, conf.mysql));

let query = function(sql, callback) {
    pool.getConnection(function(err,conn){
        if(err){
            callback(err,null,null);
        }else{
            conn.query(sql,function(qerr,vals,fields){
                //释放连接
                conn.release();
                //事件驱动回调
                callback(qerr,vals,fields);
            });
        }
    });
};



BookService = {
    jsonWrite (res,ret){
    if(typeof ret=='undefind'){
        res.json({
            code:'0',
            msg:'操作失败'
        });
    }else{
        res.json(ret);
    }
}
,

findById: function(id, ) {
        qsql = sql.findById.replace('?', id);
        query(qsql, function (qerr,vals,fields) {
            console.log(qerr);
            console.log(vals);
            console.log(fields);
        })
    }

}

module.exports = BookService;